package com.seguim.geroglifics;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Row {
	private List cols;
	public int width = 0;
	public int height = 0;
	public Row() {
		cols = new ArrayList();
	}
	public List getCols() {
		return cols;
	}
	public void addCol(Col col) {
		cols.add(col);
	}
	public int getWidth() {
		if (width == 0 || height == 0) {
			computeSize();
		}
		return width;
	}
	public int getHeigth() {
		if (width == 0 || height == 0) {
			computeSize();
		}
		return height;
	}
	public void computeSize() {
		int rowWidth = 0;
		int rowHeight = 0;
		for (Iterator symbolIter = cols.iterator(); symbolIter.hasNext();) {
			Col col = (Col) symbolIter.next();
			int colWidth = col.getWidth();
			int colHeight = col.getHeight();
			rowWidth += colWidth;
			if (rowHeight < colHeight) {
				rowHeight = colHeight;
			}
		}
		width = rowWidth;
		height = rowHeight;
	}
}
